package com.qijian.maindata.domain.query;

import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.qijian.common.utils.mybatis.WhereType;
import com.qijian.common.utils.mybatis.WhereTypeEnum;
import lombok.Data;
import lombok.ToString;

import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;


/**
 * 项目对象 查询条件类
 *
 * @author qijian
 * @date 2021-10-06
 */

@Data
@ToString
@TableName("main_project")
public class ProjectQuery {

    @WhereType(filed = "project_id")
    private Long projectId;
    @WhereType(filed = "user_id")
    private Long userId;
    @WhereType(filed = "user_id", type = WhereTypeEnum.NOTNULL)
    private Boolean userIdNotNull;
    @WhereType(filed = "bom_id")
    private Long bomId;
    @WhereType(filed = "item_id")
    private Long itemId;
    @WhereType(type = WhereTypeEnum.NULL, fields = {"main_project.user_id", "main_project.bom_id"})
    private Boolean bomIdIsNull;
    @WhereType(filed = "bom_id", type = WhereTypeEnum.NOTNULL)
    private Boolean bomIdIsNotNull;
    @WhereType(filed = "sale_id")
    private Long saleId;
    @WhereType(filed = "sale_id", type = WhereTypeEnum.IN)
    private Set<Long> saleIds;
    @WhereType(filed = "sale_detail_id", type = WhereTypeEnum.IN)
    private List<Long> saleDetailIds;
    @WhereType(filed = "contract_sale_detail_id", tableName = "sm_contract_sales_detail_project", type = WhereTypeEnum.IN)
    private List<Long> contractSaleDetailIds;
    @WhereType(filed = "sale_detail_id", type = WhereTypeEnum.NOTNULL)
    private Boolean saleDetailIdIsNotNull;
    @WhereType(filed = "bom_name", type = WhereTypeEnum.LIKE)
    private String bomName;
    @WhereType(filed = "project_type")
    private String projectType;
    @WhereType(filed = "project_no", type = WhereTypeEnum.LIKE)
    private String projectNo;
    @WhereType(filed = "project_no", type = WhereTypeEnum.EQ)
    private String projectNoEq;
    @WhereType(filed = "project_no", type = WhereTypeEnum.IN)
    private List<String> projectNos;
    @WhereType(filed = "project_name", type = WhereTypeEnum.LIKE)
    private String projectName;
    @WhereType(filed = "machine_no")
    private String machineNo;
    @WhereType(filed = "machine_no", type = WhereTypeEnum.IN)
    private Set<String> machineNos;
    @WhereType(filed = "machine_no", type = WhereTypeEnum.NEQ)
    private String machineNoNot;
    @WhereType(filed = "status")
    private Integer status;
    @WhereType(filed = "status", type = WhereTypeEnum.IN)
    private List<Integer> statusList;
    @WhereType(filed = "status", type = WhereTypeEnum.NEQ)
    private Integer statusNot;
    @WhereType(filed = "status", type = WhereTypeEnum.NOTIN)
    private List<Integer> statusNots;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @WhereType(filed = "start_time")
    private Date startTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @WhereType(filed = "end_time")
    private Date endTime;
    @WhereType(filed = "end_time", type = WhereTypeEnum.NULL)
    private Boolean endTimeIsNull;
    @WhereType(filed = "end_time", type = WhereTypeEnum.NOTNULL)
    private Boolean endTimeIsNotNull;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @WhereType(filed = "end_time", type = WhereTypeEnum.GT)
    private Date endTimeGT;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @WhereType(filed = "end_time", type = WhereTypeEnum.LT)
    private Date endTimeLT;
    @WhereType(filed = "is_dist")
    private Boolean isDist;
    @WhereType(filed = "approval_by")
    private String approvalBy;
    @WhereType(filed = "approval_time")
    private Date approvalTime;
    @WhereType(filed = "approval_status")
    private String approvalStatus;
    @WhereType(filed = "project_id", type = WhereTypeEnum.IN)
    private Set<Long> ids;
    @WhereType(filed = "project_id", type = WhereTypeEnum.NOTIN)
    private List<Long> idsNotIn;
    @WhereType(filed = "nick_name", tableName = "u", type = WhereTypeEnum.LIKE)
    private String nickName;
    @WhereType(filed = "item_name", tableName = "main_item", type = WhereTypeEnum.LIKE)
    private String itemName;
    @WhereType(deptTableName = "u", userTableName = "main_project")
    private Boolean dataScope;
    @WhereType(filed = "fid", type = WhereTypeEnum.IN)
    private List<Long> fids;
    @WhereType(filed = "fid", type = WhereTypeEnum.NOTIN)
    private List<Long> fidsNotIn;

    @WhereType(tableName = "s", filed = "out_quantity", func = "{2}<s.quantity")
    private Boolean isStock;

    @WhereType(ignore = true)
    private Integer level;

    @WhereType(filed = "is_point")
    private Boolean isPoint;

    @WhereType(tableName = "sm_contract_sales_detail", filed = "id", type = WhereTypeEnum.NULL)
    private Boolean saleDetailIdIsNull;

    @WhereType(func = "(fin_budget_detail.id is null or fin_budget.id is null)" +
            " and main_project.project_no not like 'GZ%'" +
            " and main_project.project_no not like 'SB%'" +
            " and main_project.project_no not like 'YSGZ%'" +
            " and main_project.project_no not like 'YH%'"
    )
    private Boolean notExistBudget;

    @WhereType(func = "(im_logistics_delivery_detail.id is null or im_logistics_delivery.id is null)" +
            " and main_project.status in (0,4)" +
            " and main_project.customer_name != '振江新能源'")
    private Boolean notExistLogistics;

    @WhereType(func = "main_bom.bom_id is not null" +
            " and (main_bom_material.id is null or main_bom_material.project_nos is null or main_bom_material.project_nos = '')")
    private Boolean notExistBomMaterial;

    private String createBy;

    @WhereType(func = "main_project.update_time < DATE_FORMAT(DATE_SUB(NOW(),INTERVAL {1} DAY),'%Y-%m-%d')")
    private Integer updateTimeGeDays;

    @WhereType(tableName = "main_bom", filed = "create_by")
    private String bomCreateBy;

    @WhereType(tableName = "main_bom", filed = "create_by", type = WhereTypeEnum.IN)
    private Collection<String> bomCreateByIn;

    @WhereType(tableName = "liu", filed = "user_id")
    private Long logisticsInquiryUserId;
    @WhereType(tableName = "liu", filed = "user_id", type = WhereTypeEnum.NULL)
    private Boolean logisticsInquiryUserIdNull;

    @WhereType(func = "NOT EXISTS (SELECT 1 FROM main_adjust_order WHERE source_id = main_project.project_id)")
    private Boolean isAdjustOrder;

    @WhereType(func = "EXISTS (SELECT 1 FROM main_project g WHERE g.is_del = 0 AND g.bom_id IS NOT NULL AND g.status not in (0, 4) AND g.project_id=main_project.project_id )")
    private Boolean isInProcess;

    @WhereType(func = "EXISTS (SELECT 1 FROM main_project g WHERE g.is_del = 0 AND g.bom_id IS NOT NULL AND g.status in (0, 4) AND g.project_id=main_project.project_id )")
    private Boolean isFinish;

    @WhereType(func = "EXISTS (SELECT 1 FROM main_project g WHERE g.is_del = 0 AND g.bom_id IS NOT NULL AND g.project_id=main_project.project_id )")
    private Boolean isAll;

    @WhereType(tableName = "main_item", filed = "item_code", type = WhereTypeEnum.LIKE)
    private String itemCode;
    @WhereType(filed = "is_shipped", type = WhereTypeEnum.EQ)
    private String isShipped;

    @WhereType(fields = {"main_item.item_name", "main_project.customer_name", "main_project.project_no", "sys_user.nick_name"}, type = WhereTypeEnum.LIKE)
    private String condition;

    //    @WhereType(filed = "machine_no",type = WhereTypeEnum.GT)
    //机台号数字和字符串转换有问题，手动处理下这个参数
    @WhereType(ignore = true)
    private String startMachineNo;

    @WhereType(ignore = true)
    private Long detailId;

    @WhereType(filed = "customer_name", type = WhereTypeEnum.EQ)
    private String customerNameEq;


    @WhereType(func = " exists( select 1 from sm_contract_sales_detail_project scsdp  where contract_sale_detail_id ={1} and project_id = main_project.project_id)")
    private Long salesContractDetailId;

    @WhereType(filed = "customer_id", tableName = "main_project", type = WhereTypeEnum.NOTNULL)
    private Boolean customerIdNotNUll;

    @WhereType(ignore = true)
    private Boolean unBindFlag;

    @WhereType(func = "main_project.sale_id is null  and main_project.create_time > {1} " +
            " and main_project.project_machine_no not like 'YHP%'" +
            " and main_project.project_machine_no not like 'SB%'" +
            " and main_project.project_machine_no not like 'GZ%'" +
            " and main_project.project_machine_no not like 'YSGZ%'" +
            " and main_project.project_machine_no not like 'WX%'" +
            " and main_project.project_machine_no not like '%BL%'" +
            " and main_project.project_machine_no not like 'KT%'" +
            " and main_project.project_machine_no not like 'KF%'" +
            " and main_project.project_machine_no not like 'ZPGZ%'" +
            " and main_project.project_machine_no not like 'NDP%'")
    private String unBindWithStartDate;

    @WhereType(filed = "create_by", tableName = "main_project", type = WhereTypeEnum.EQ)
    private String unBindProjectCreateBy;

    @WhereType(func = " main_project.project_no not like 'BK%'")
    private String ignoreBK;

    //是否已排产
    @WhereType(ignore = true)
    private Boolean isPlan;

    @WhereType(filed = "project_machine_no", type = WhereTypeEnum.EQ)
    private String projectMachineNo;
    @WhereType(filed = "project_machine_no", type = WhereTypeEnum.IN)
    private Set<String> projectMachineNoIn;

    @WhereType(filed = "titanium_flag", type = WhereTypeEnum.EQ)
    public String titaniumFlag;

    @WhereType(filed = "create_time", type = WhereTypeEnum.GT)
    private Date createTime;


    //是否已排产
    @WhereType(ignore = true)
    private Boolean isAllocated;


}
